Option Strict On
Option Explicit On 

Public Class ULookup
    Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents lblParentRelation As System.Windows.Forms.Label
    Friend WithEvents cboParentRelation As System.Windows.Forms.ComboBox
    Friend WithEvents lblStartupTable As System.Windows.Forms.Label
    Friend WithEvents cboStartupTable As System.Windows.Forms.ComboBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(ULookup))
        Me.lblParentRelation = New System.Windows.Forms.Label
        Me.cboParentRelation = New System.Windows.Forms.ComboBox
        Me.lblStartupTable = New System.Windows.Forms.Label
        Me.cboStartupTable = New System.Windows.Forms.ComboBox
        Me.SuspendLayout()
        '
        'lblParentRelation
        '
        Me.lblParentRelation.AccessibleDescription = resources.GetString("lblParentRelation.AccessibleDescription")
        Me.lblParentRelation.AccessibleName = resources.GetString("lblParentRelation.AccessibleName")
        Me.lblParentRelation.Anchor = CType(resources.GetObject("lblParentRelation.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.lblParentRelation.AutoSize = CType(resources.GetObject("lblParentRelation.AutoSize"), Boolean)
        Me.lblParentRelation.Dock = CType(resources.GetObject("lblParentRelation.Dock"), System.Windows.Forms.DockStyle)
        Me.lblParentRelation.Enabled = CType(resources.GetObject("lblParentRelation.Enabled"), Boolean)
        Me.lblParentRelation.Font = CType(resources.GetObject("lblParentRelation.Font"), System.Drawing.Font)
        Me.lblParentRelation.Image = CType(resources.GetObject("lblParentRelation.Image"), System.Drawing.Image)
        Me.lblParentRelation.ImageAlign = CType(resources.GetObject("lblParentRelation.ImageAlign"), System.Drawing.ContentAlignment)
        Me.lblParentRelation.ImageIndex = CType(resources.GetObject("lblParentRelation.ImageIndex"), Integer)
        Me.lblParentRelation.ImeMode = CType(resources.GetObject("lblParentRelation.ImeMode"), System.Windows.Forms.ImeMode)
        Me.lblParentRelation.Location = CType(resources.GetObject("lblParentRelation.Location"), System.Drawing.Point)
        Me.lblParentRelation.Name = "lblParentRelation"
        Me.lblParentRelation.RightToLeft = CType(resources.GetObject("lblParentRelation.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.lblParentRelation.Size = CType(resources.GetObject("lblParentRelation.Size"), System.Drawing.Size)
        Me.lblParentRelation.TabIndex = CType(resources.GetObject("lblParentRelation.TabIndex"), Integer)
        Me.lblParentRelation.Text = resources.GetString("lblParentRelation.Text")
        Me.lblParentRelation.TextAlign = CType(resources.GetObject("lblParentRelation.TextAlign"), System.Drawing.ContentAlignment)
        Me.lblParentRelation.Visible = CType(resources.GetObject("lblParentRelation.Visible"), Boolean)
        '
        'cboParentRelation
        '
        Me.cboParentRelation.AccessibleDescription = resources.GetString("cboParentRelation.AccessibleDescription")
        Me.cboParentRelation.AccessibleName = resources.GetString("cboParentRelation.AccessibleName")
        Me.cboParentRelation.Anchor = CType(resources.GetObject("cboParentRelation.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.cboParentRelation.BackgroundImage = CType(resources.GetObject("cboParentRelation.BackgroundImage"), System.Drawing.Image)
        Me.cboParentRelation.Dock = CType(resources.GetObject("cboParentRelation.Dock"), System.Windows.Forms.DockStyle)
        Me.cboParentRelation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboParentRelation.Enabled = CType(resources.GetObject("cboParentRelation.Enabled"), Boolean)
        Me.cboParentRelation.Font = CType(resources.GetObject("cboParentRelation.Font"), System.Drawing.Font)
        Me.cboParentRelation.ImeMode = CType(resources.GetObject("cboParentRelation.ImeMode"), System.Windows.Forms.ImeMode)
        Me.cboParentRelation.IntegralHeight = CType(resources.GetObject("cboParentRelation.IntegralHeight"), Boolean)
        Me.cboParentRelation.ItemHeight = CType(resources.GetObject("cboParentRelation.ItemHeight"), Integer)
        Me.cboParentRelation.Location = CType(resources.GetObject("cboParentRelation.Location"), System.Drawing.Point)
        Me.cboParentRelation.MaxDropDownItems = CType(resources.GetObject("cboParentRelation.MaxDropDownItems"), Integer)
        Me.cboParentRelation.MaxLength = CType(resources.GetObject("cboParentRelation.MaxLength"), Integer)
        Me.cboParentRelation.Name = "cboParentRelation"
        Me.cboParentRelation.RightToLeft = CType(resources.GetObject("cboParentRelation.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.cboParentRelation.Size = CType(resources.GetObject("cboParentRelation.Size"), System.Drawing.Size)
        Me.cboParentRelation.TabIndex = CType(resources.GetObject("cboParentRelation.TabIndex"), Integer)
        Me.cboParentRelation.Text = resources.GetString("cboParentRelation.Text")
        Me.cboParentRelation.Visible = CType(resources.GetObject("cboParentRelation.Visible"), Boolean)
        '
        'lblStartupTable
        '
        Me.lblStartupTable.AccessibleDescription = resources.GetString("lblStartupTable.AccessibleDescription")
        Me.lblStartupTable.AccessibleName = resources.GetString("lblStartupTable.AccessibleName")
        Me.lblStartupTable.Anchor = CType(resources.GetObject("lblStartupTable.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.lblStartupTable.AutoSize = CType(resources.GetObject("lblStartupTable.AutoSize"), Boolean)
        Me.lblStartupTable.Dock = CType(resources.GetObject("lblStartupTable.Dock"), System.Windows.Forms.DockStyle)
        Me.lblStartupTable.Enabled = CType(resources.GetObject("lblStartupTable.Enabled"), Boolean)
        Me.lblStartupTable.Font = CType(resources.GetObject("lblStartupTable.Font"), System.Drawing.Font)
        Me.lblStartupTable.Image = CType(resources.GetObject("lblStartupTable.Image"), System.Drawing.Image)
        Me.lblStartupTable.ImageAlign = CType(resources.GetObject("lblStartupTable.ImageAlign"), System.Drawing.ContentAlignment)
        Me.lblStartupTable.ImageIndex = CType(resources.GetObject("lblStartupTable.ImageIndex"), Integer)
        Me.lblStartupTable.ImeMode = CType(resources.GetObject("lblStartupTable.ImeMode"), System.Windows.Forms.ImeMode)
        Me.lblStartupTable.Location = CType(resources.GetObject("lblStartupTable.Location"), System.Drawing.Point)
        Me.lblStartupTable.Name = "lblStartupTable"
        Me.lblStartupTable.RightToLeft = CType(resources.GetObject("lblStartupTable.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.lblStartupTable.Size = CType(resources.GetObject("lblStartupTable.Size"), System.Drawing.Size)
        Me.lblStartupTable.TabIndex = CType(resources.GetObject("lblStartupTable.TabIndex"), Integer)
        Me.lblStartupTable.Text = resources.GetString("lblStartupTable.Text")
        Me.lblStartupTable.TextAlign = CType(resources.GetObject("lblStartupTable.TextAlign"), System.Drawing.ContentAlignment)
        Me.lblStartupTable.Visible = CType(resources.GetObject("lblStartupTable.Visible"), Boolean)
        '
        'cboStartupTable
        '
        Me.cboStartupTable.AccessibleDescription = resources.GetString("cboStartupTable.AccessibleDescription")
        Me.cboStartupTable.AccessibleName = resources.GetString("cboStartupTable.AccessibleName")
        Me.cboStartupTable.Anchor = CType(resources.GetObject("cboStartupTable.Anchor"), System.Windows.Forms.AnchorStyles)
        Me.cboStartupTable.BackgroundImage = CType(resources.GetObject("cboStartupTable.BackgroundImage"), System.Drawing.Image)
        Me.cboStartupTable.Dock = CType(resources.GetObject("cboStartupTable.Dock"), System.Windows.Forms.DockStyle)
        Me.cboStartupTable.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboStartupTable.Enabled = CType(resources.GetObject("cboStartupTable.Enabled"), Boolean)
        Me.cboStartupTable.Font = CType(resources.GetObject("cboStartupTable.Font"), System.Drawing.Font)
        Me.cboStartupTable.ImeMode = CType(resources.GetObject("cboStartupTable.ImeMode"), System.Windows.Forms.ImeMode)
        Me.cboStartupTable.IntegralHeight = CType(resources.GetObject("cboStartupTable.IntegralHeight"), Boolean)
        Me.cboStartupTable.ItemHeight = CType(resources.GetObject("cboStartupTable.ItemHeight"), Integer)
        Me.cboStartupTable.Location = CType(resources.GetObject("cboStartupTable.Location"), System.Drawing.Point)
        Me.cboStartupTable.MaxDropDownItems = CType(resources.GetObject("cboStartupTable.MaxDropDownItems"), Integer)
        Me.cboStartupTable.MaxLength = CType(resources.GetObject("cboStartupTable.MaxLength"), Integer)
        Me.cboStartupTable.Name = "cboStartupTable"
        Me.cboStartupTable.RightToLeft = CType(resources.GetObject("cboStartupTable.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.cboStartupTable.Size = CType(resources.GetObject("cboStartupTable.Size"), System.Drawing.Size)
        Me.cboStartupTable.TabIndex = CType(resources.GetObject("cboStartupTable.TabIndex"), Integer)
        Me.cboStartupTable.Text = resources.GetString("cboStartupTable.Text")
        Me.cboStartupTable.Visible = CType(resources.GetObject("cboStartupTable.Visible"), Boolean)
        '
        'ULookup
        '
        Me.AccessibleDescription = resources.GetString("$this.AccessibleDescription")
        Me.AccessibleName = resources.GetString("$this.AccessibleName")
        Me.AutoScroll = CType(resources.GetObject("$this.AutoScroll"), Boolean)
        Me.AutoScrollMargin = CType(resources.GetObject("$this.AutoScrollMargin"), System.Drawing.Size)
        Me.AutoScrollMinSize = CType(resources.GetObject("$this.AutoScrollMinSize"), System.Drawing.Size)
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.Controls.Add(Me.lblStartupTable)
        Me.Controls.Add(Me.cboStartupTable)
        Me.Controls.Add(Me.lblParentRelation)
        Me.Controls.Add(Me.cboParentRelation)
        Me.Enabled = CType(resources.GetObject("$this.Enabled"), Boolean)
        Me.Font = CType(resources.GetObject("$this.Font"), System.Drawing.Font)
        Me.ImeMode = CType(resources.GetObject("$this.ImeMode"), System.Windows.Forms.ImeMode)
        Me.Location = CType(resources.GetObject("$this.Location"), System.Drawing.Point)
        Me.Name = "ULookup"
        Me.RightToLeft = CType(resources.GetObject("$this.RightToLeft"), System.Windows.Forms.RightToLeft)
        Me.Size = CType(resources.GetObject("$this.Size"), System.Drawing.Size)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Event ValueChanged As EventHandler

    Private Sub ULookup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler cboParentRelation.SelectionChangeCommitted, AddressOf OnValueChanged
        AddHandler cboStartupTable.SelectionChangeCommitted, AddressOf OnValueChanged
    End Sub

    Protected Sub OnValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        RaiseEvent ValueChanged(Me, New EventArgs)
    End Sub

    Public Sub Prepare(ByVal section As Model10.Section)
        cboParentRelation.Items.Clear()

        Dim rlt As Model10.Relation
        For Each rlt In section.Table.ParentRelations
            cboParentRelation.Items.Add(rlt)
        Next : rlt = Nothing
        '-------------------
        cboStartupTable.Items.Clear()
        cboStartupTable.Items.Add("[None]")

        Dim tbl As Model10.Table
        For Each tbl In section.Table.Presentation.Tables
            If Not tbl Is section.Table Then
                cboStartupTable.Items.Add(tbl)
            End If
        Next : tbl = Nothing
    End Sub

    Public Sub Read(ByVal lookup As Model10.Lookup)
        cboParentRelation.SelectedItem = lookup.ParentRelation
        If lookup.StartupTable Is Nothing Then
            cboStartupTable.SelectedItem = "[None]"
        Else
            cboStartupTable.SelectedItem = lookup.StartupTable
        End If
    End Sub
    Public Sub Write(ByVal lookup As Model10.Lookup)
        lookup.ParentRelation = CType(cboParentRelation.SelectedItem, Model10.Relation)
        If cboStartupTable.Text = "[None]" Then
            lookup.StartupTable = Nothing
        Else
            lookup.StartupTable = CType(cboStartupTable.SelectedItem, Model10.Table)
        End If
    End Sub
End Class